package com.polaris.live.adapter.party

import android.view.View
import androidx.lifecycle.LifecycleCoroutineScope
import com.blankj.utilcode.util.StringUtils
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.common.util.AppCodeUtils
import com.polaris.live.databinding.AdapterInteractionEmojiBinding
import com.polaris.live.popup.party.InteractionEmojiPopup
import com.polaris.live.resp.back_resp.LiveEmojiResp
import com.polaris.live.translation.R
import com.polaris.live.utils.CommonUtils.toBoolean
import com.polaris.live.utils.playAsync

/**
 *  互动Emojiadapter
 * @author Created by 天晴 on 2024/2/27 19:39
 * @since 1.0.0
 **/
class InteractionEmojiAdapter(
    private val lifecycleScope: LifecycleCoroutineScope,
) : BaseBindingAdapter<AdapterInteractionEmojiBinding, LiveEmojiResp>() {

    override fun convert(
        holder: VBViewHolder<AdapterInteractionEmojiBinding>,
        item: LiveEmojiResp,
    ) {
        holder.vb.apply {
            pagEmoji.playAsync(lifecycleScope, item.emoji)

            if (item.available.toBoolean()) {
                pagEmoji.alpha = 1.0f
            } else {
                pagEmoji.alpha = 0.4f
            }
            levelView.visibility = View.GONE
            vipRl.visibility = View.GONE
            if (item.objectId != null) {
                when (item.type) {
                    InteractionEmojiPopup.EMOJI_RICH -> {
                        levelView.visibility = View.VISIBLE
                        levelView.setNormalRichsLevel(item.objectId)
                    }

                    InteractionEmojiPopup.EMOJI_VIP -> {
                        vipTv.text = StringUtils.getString(R.string.vip_level, item.objectId)
                        vipRl.setBackgroundResource(if (AppCodeUtils.isAR()) com.polaris.live.R.drawable.vip_emoji_bg_rtl else com.polaris.live.R.drawable.vip_emoji_bg)
                        vipRl.visibility = View.VISIBLE
                    }
                }

            }

        }
    }
}